extends CharaV


#静态角色专用CharaV
onready var player = $player
onready var pic = $pic
func _ready():
	pass # Replace with function body.

var utils
func init(obj,isDrag = false):
	utils = sys.get_node("VEBase").utils
	objVInit(obj)
	self.isDrag = isDrag
	chara = obj
	#chara.connect("onDeath",self,"rDeath")
	self.chara.connect("onHurt",self,"rHurt")
	self.chara.connect("onPlus",self,"rPlus")
	self.chara.connect("onPlusLv",self,"rPlusLv")
	chara.connect("onPlayAnim",self,"playAnim")
	$ui/hpBar.init(obj)
	$ui/dragK.init(self)
	$ui/v/popLv.init(chara)
	sys.addTip($ui/dragK,obj.dec)
	for i in self.chara.eqps.items:
		var btn = preload("res://tscn/item/itemChaBtn.tscn").instance()
		eqps.add_child(btn)
		btn.init(i)
	self.chara.eqps.connect("onUp",self,"up")
	$ui/dragK.chara = chara
	self.chara.connect("onNewBuffEff",self,"newBuffEff")
	for i in chara.affs:
		if i.get("effId") != null:
			newBuffEff(i)
	#$hpBar.position.y = chara.imgCenterPos.y * 2
	chara.connect("onPlusXp",self,"_onPlusXp")
	$ui/buffs.init(chara)
	$ui/buffs.visible = false
	
	if obj.staticPic is String:
		obj.staticPic = load(obj.staticPic)
	$pic.texture = obj.staticPic
	
func objVInit(obj):
	self.obj = obj
	obj.vis = self
	if isItem :
		setProcess(false)
		return
	obj.connect("onSetCell",self,"rSetCell")
	#obj.connect("onSetGoalCell",self,"rSetGoalCell"
	obj.connect("onDel",self,"_del")
	obj.connect("onUpPosition",self,"rUpPos")
	obj.connect("onSetVisible",self,"rSetVisible")
	upPosition()
	rSetVisible()

func _moveStart():
	direToPos(nextTgPos)
	# if obj.nowAnim != "move":
	# 	obj.playAnim("move")

func playAnim(id,spd = 1.0):
	if player.has_animation(id) == false:
		id = "atk"
		sys.playSe("knife2.wav")
	elif id == "buff" :
		sys.playSe("FlyObj.wav")
	elif id == "atk2" :
		sys.playSe("knife2.wav")
		
	player.play(id)
	player.speed_scale = spd
	if chara.nowAnim != "move" && chara.aiCha != null:
		direToPos(chara.aiCha.position)
	# var t = player.frames.get_frame(id,0)
	pic.position.y = -pic.get_height() * pic.scale.y * 0.5  + 5
